package cn.edu.scau.cmi.limingben.adapter;

import cn.edu.scau.cmi.limingben.adapter.model.DC5V;
import cn.edu.scau.cmi.limingben.adapter.model.Pow220V;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

import java.net.URL;
import java.util.ResourceBundle;

public class Controller implements Initializable {
    @FXML
    public ChoiceBox class_choice;
    @FXML
    public ChoiceBox obj_choice;
    @FXML
    public TextArea class_text;
    @FXML
    public TextArea obj_text;

    @Override
    public void initialize(URL location, ResourceBundle resources){
        class_choice.getItems().addAll("220V","DC 5V");
        obj_choice.getItems().addAll("220V","AC 5V");
        class_choice.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                if (newValue.equals("220V")){
                    class_text.setText(new Pow220V().out()+"V");
                }
                else {
                    class_text.setText(new DC5V().out5() + "V DC");
                }
            }
        });
        obj_choice.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                if (newValue.equals("220V")){
                    obj_text.setText(new Pow220V().out()+"V");
                }
                else {
                    obj_text.setText(new DC5V().out5() + "V AC");
                }
            }
        });
    }
}
